package com.blog.utils;

import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.ControllerAdvice;

import java.util.Random;

@Component
public class CaptchaGenerator {
    private static final String NUMBERS = "0123456789";
    private static final int CODE_LENGTH = 4;
    private static final Random random = new Random();

    /**
     * 生成4位纯数字验证码
     */
    public String generateNumericCode() {
        StringBuilder sb = new StringBuilder(CODE_LENGTH);
        for (int i = 0; i < CODE_LENGTH; i++) {
            int index = random.nextInt(NUMBERS.length());
            sb.append(NUMBERS.charAt(index));
        }
        return sb.toString();
    }
}
